package cn.com.yusys.yusp.admin.web.rest;

import cn.com.yusys.yusp.admin.domain.AdminSmMenu;
import cn.com.yusys.yusp.admin.service.AdminSmMenuService;
import cn.com.yusys.yusp.commons.mapper.QueryModel;
import cn.com.yusys.yusp.commons.service.CommonService;
import cn.com.yusys.yusp.commons.web.rest.CommonResource;
import cn.com.yusys.yusp.commons.web.rest.dto.ResultDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @项目名称: yusp-admin
 * @类名称: AdminMenuConfigResource
 * @类描述: 菜单配置接口层
 * @功能描述:
 * @创建人: weimei1@yusys.com.cn
 * @创建时间: 2017-12-23 10:25
 * @修改备注:
 * @修改记录: 修改时间 修改人员 修改原因
 *        -------------------------------------------------------------
 * @version 1.0.0
 * @Copyright (c) 2017宇信科技-版权所有
 */
@RestController
@RequestMapping("/api/adminsmmenu")
public class AdminSmMenuResource extends CommonResource<AdminSmMenu, String> {

    @Autowired
    private AdminSmMenuService adminSmMenuService;

    @Override
    protected CommonService getCommonService() {
        return this.adminSmMenuService;
    }

    /**
     * @方法名称:getMenuTree
     * @方法描述:菜单树初始化查询
     * @参数与返回说明:
     * @算法描述:
     */
    @GetMapping("/menutreequery")
    public ResultDto<List<Map<String, Object>>> getMenuTree(@RequestParam String sysId,boolean lazy,String menuId) {
        List<Map<String, Object>> list = adminSmMenuService.getMenuTree(sysId,lazy,menuId);
        return new ResultDto<List<Map<String, Object>>>(list.size(),list);
    }

    /**
     * @方法名称:getMenuInfo
     * @方法描述:菜单节点信息查询
     * @参数与返回说明:
     * @算法描述:
     */
    @GetMapping("/menuinfoquery")
    public ResultDto<Map<String, Object>> getMenuInfo(@RequestParam(required = true) String menuId) {
        return new ResultDto<Map<String, Object>>(1, adminSmMenuService.getMenuInfo(menuId));
    }

    /**
     * @方法名称: createMenu
     * @方法描述: 新增菜单
     * @参数与返回说明:
     * @算法描述:
     */
    @PostMapping("/createmenu")
    public ResultDto<Integer> createMenu(@RequestBody AdminSmMenu adminSmMenu) {
        int result = this.adminSmMenuService.createMenu(adminSmMenu);
        ResultDto<Integer> resultDto = new ResultDto<>();
        if(result >= 1){
            resultDto.setMessage("添加菜单"+ adminSmMenu.getMenuName());
        }
        resultDto.setData(result);
        return resultDto;
    }

    /**
     * @方法名称: editMenu
     * @方法描述: 修改菜单
     * @参数与返回说明:
     * @算法描述:
     */
    @PostMapping("/editmenu")
    public ResultDto<Integer> editMenu(@RequestBody AdminSmMenu adminSmMenu) {
        int result = this.adminSmMenuService.editMenu(adminSmMenu);
        ResultDto<Integer> resultDto = new ResultDto<>();
        if(result >=1 ){
            resultDto.setMessage("菜单"+adminSmMenu.getMenuName()+"修改成功！");
        }
        resultDto.setData(result);
        return resultDto;
    }

    /**
     * @方法名称: deleteMenu
     * @方法描述: 删除菜单
     * @参数与返回说明:
     * @算法描述:
     */
    @PostMapping("/deletemenu")
    public ResultDto<Integer> deleteMenu(@RequestBody String menuId) {
        int result = this.adminSmMenuService.deleteMenu(menuId);
        ResultDto<Integer> resultDto = new ResultDto<>();
        if(result >= 1){
            resultDto.setMessage("成功删除菜单"+menuId+"");
        }
        resultDto.setData(result);
        return resultDto;
    }

    /**
     * @方法名称: getFuncInfo
     * @方法描述: 业务功能列表查询
     * @参数与返回说明:
     * @算法描述:
     */
    @GetMapping("/funclistquery")
    public ResultDto<List<Map<String, Object>>> getFuncInfo(QueryModel queryModel) {
        List<Map<String, Object>> list = adminSmMenuService.getFuncInfo(queryModel);
        return new ResultDto<List<Map<String, Object>>>(list);
    }
}
